package com.ruoyi.system.js;

import com.ruoyi.system.domain.Forest.IotDeviceInfo;
import org.nutz.el.El;
import org.nutz.lang.Lang;
import org.nutz.lang.util.Context;
//import org.nutz.lang.util.Context;
import java.math.BigDecimal;
import java.util.Arrays;

public class JsEngine {
    //https://nutzam.com/core/el/overview.html#ndoc-8
    public static void main(String[] args) {
        El exp = new El("area*price*0.5+heat*heatPrice/1000.0");  // 预编译结果为一个 El 对象
//
        Context context = Lang.context();
        context.set("area", new BigDecimal(10));
        context.set("price", new BigDecimal(26));
        context.set("heat", new BigDecimal("10"));
        context.set("heatPrice", new BigDecimal("134.10"));


        System.out.println(exp.eval(context));  // 将打印 100

        System.out.println(exp.eval("5>3"));

//        Context context = Lang.context();
        IotDeviceInfo iotDeviceInfo = new IotDeviceInfo();
        iotDeviceInfo.setDeviceData1(0.0);
        iotDeviceInfo.setDeviceData3(0.0);

        context.set("iot",iotDeviceInfo);
        System.out.println(El.eval(context,"iot.deviceData1==0&&iot.deviceData3==0"));

//        Context context = Lang.context();
        context.set("map",Lang.map("{x:10, y:5}"));

        System.out.println(El.eval(context,"map['x'] * map['y']"));
// 输出为  50
    }

}
